/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tracker.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : 12 November 2012
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
 */
@Entity
@Table(name = "Torrents")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TorrentsEntity.findAll", query = "SELECT t FROM TorrentsEntity t"),
    @NamedQuery(name = "TorrentsEntity.findByTorrentId", query = "SELECT t FROM TorrentsEntity t WHERE t.torrentId = :torrentId"),
    @NamedQuery(name = "TorrentsEntity.findByTorrentName", query = "SELECT t FROM TorrentsEntity t WHERE t.torrentName = :torrentName"),
    @NamedQuery(name = "TorrentsEntity.findByTorrentDescription", query = "SELECT t FROM TorrentsEntity t WHERE t.torrentDescription = :torrentDescription"),
    @NamedQuery(name = "TorrentsEntity.findByTorrentTime", query = "SELECT t FROM TorrentsEntity t WHERE t.torrentTime = :torrentTime")})
/*
SELECT usr.UserId, usr.UserName, point.TorrentId, tor.TorrentName, tor.TorrentTime
FROM Points point
INNER JOIN Users usr
ON point.UserId = usr.UserId
INNER JOIN Torrents tor
ON point.TorrentId = tor.TorrentId
WHERE point.UserId = :userId
*/
public class TorrentsEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue(strategy = GenerationType.IDENTITY) //Auto-Increment
    @Column(name = "TorrentId")
    private Integer torrentId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "TorrentName")
    private String torrentName;
    @Size(max = 1000)
    @Column(name = "TorrentDescription")
    private String torrentDescription;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "TorrentTime")
    private String torrentTime;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "torrentId")
    private Collection<CommentsEntity> commentsEntityCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "torrentId")
    private Collection<PointsEntity> pointsEntityCollection;

    public TorrentsEntity() {
    }

    public TorrentsEntity(Integer torrentId) {
        this.torrentId = torrentId;
    }

    public TorrentsEntity(Integer torrentId, String torrentName, String torrentTime) {
        this.torrentId = torrentId;
        this.torrentName = torrentName;
        this.torrentTime = torrentTime;
    }

    public Integer getTorrentId() {
        return torrentId;
    }

    public void setTorrentId(Integer torrentId) {
        this.torrentId = torrentId;
    }

    public String getTorrentName() {
        return torrentName;
    }

    public void setTorrentName(String torrentName) {
        this.torrentName = torrentName;
    }

    public String getTorrentDescription() {
        return torrentDescription;
    }

    public void setTorrentDescription(String torrentDescription) {
        this.torrentDescription = torrentDescription;
    }

    public String getTorrentTime() {
        return torrentTime;
    }

    public void setTorrentTime(String torrentTime) {
        this.torrentTime = torrentTime;
    }

    @XmlTransient
    public Collection<CommentsEntity> getCommentsEntityCollection() {
        return commentsEntityCollection;
    }

    public void setCommentsEntityCollection(Collection<CommentsEntity> commentsEntityCollection) {
        this.commentsEntityCollection = commentsEntityCollection;
    }

    @XmlTransient
    public Collection<PointsEntity> getPointsEntityCollection() {
        return pointsEntityCollection;
    }

    public void setPointsEntityCollection(Collection<PointsEntity> pointsEntityCollection) {
        this.pointsEntityCollection = pointsEntityCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (torrentId != null ? torrentId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TorrentsEntity)) {
            return false;
        }
        TorrentsEntity other = (TorrentsEntity) object;
        if ((this.torrentId == null && other.torrentId != null) || (this.torrentId != null && !this.torrentId.equals(other.torrentId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "tracker.entity.TorrentsEntity[ torrentId=" + torrentId + " ]";
    }

}
